<template>
	<view class="content with-tabbar">
		<scroll-view v-if="postForm" class="pt-18 pb-18 pl-30 pr-30 bg-fff" style="white-space: normal;" scroll-y>
			<div class=" ">
				<div class="head flex-center pb-34 bor-b" @click="toEdit('user', '', postForm.id)">
					<image v-if="postForm.headImg" class="headImg img-104" mode="aspectFill"
						:src="postForm.headImg.indexOf('https://') > -1 ? postForm.headImg : baseUrl + postForm.headImg" />
					<image v-else class="headImg img-104" mode="aspectFill"
						src="https://xingangtong.oss-cn-beijing.aliyuncs.com/common/头像更换.png" />
					<!-- <image class="headImg img-104" mode="aspectFill" :src="baseUrl + postForm.headImg" /> -->
					<div class="ml-28">
						<div class="fontS28 font-500"><span class="fontS40 ">{{ postForm.name || '' }}·</span>{{
							postForm.sex
								=== '0' ? '男' :
								'女' }}</div>
						<div class="fontS24 color6 mt-8">{{ postForm.experienceRequireName || '' }} ｜ {{
							postForm.highEducationName || '' }}
							|
							{{ postForm.age || '' }}岁 ｜ {{ postForm.cityName || '' }}
						</div>
					</div>
					<div class="iconfont icon-bianji fontS32 ml-auto"></div>
				</div>
				<div class="pt-34 pb-34 bor-b">
					<div class="font-bold fontS36 color-0d0 mb-14">联系方式</div>
					<div class="flex-center" @click="toEdit('contact', '', postForm.id)">
						<div>
							<div class="flex-center mt-10 lh-50 fontS28 color-6">
								<div class="iconfont icon-xiaotubiao-01"></div>
								<div class="ml-20">{{ postForm.phone || '' }}</div>
							</div>
							<div class="flex-center mt-10 lh-50 fontS28 color-6" v-if="postForm.wx">
								<div class="iconfont icon-xiaotubiao-02"></div>
								<div class="ml-20">{{ postForm.wx || '' }}</div>
							</div>
							<div class="flex-center mt-10 lh-50 fontS28 color-6" v-if="postForm.email">
								<div class="iconfont icon-xiaotubiao-03"></div>
								<div class="ml-20">{{ postForm.email || '' }}</div>
							</div>
						</div>
						<div class="ml-auto fontS28 iconfont icon-youjiantou color-6 font-bold"></div>
					</div>
				</div>
				<div class="pt-34 pb-34 bor-b">
					<div class="font-bold fontS36 color-0d0 mb-14">求职状态</div>
					<picker mode="selector" @change="change($event, 'jobSeek')" :value="jobSeekValue"
						:range="jobSeekList" range-key="label">
						<view class=" resume-box lh-50 flex align-center color-0d0 fontS28 ">
							<view class="form-cnt">
								<div class="radio">{{ jobSeekList[jobSeekValue].label }}
								</div>
							</view>
							<div class="ml-auto iconfont icon-youjiantou"></div>
						</view>
					</picker>

				</div>
				<div class="pt-34 pb-34 bor-b" @click="toEdit('creat4')">
					<div class="font-bold fontS36 color-0d0 mb-14">个人优势</div>
					<div class="flex-center lh-50 color-0d0 fontS28">
						<div class="fontE2">{{ postForm.advantage || '' }}</div>
						<div class="ml-auto iconfont icon-youjiantou color-6 font-bold">
						</div>

					</div>
				</div>

				<div class="pt-34 pb-14 bor-b">
					<div class="flex-center" @click="toEdit('creat5', null, null, null, 'bind')">
						<div class="font-bold fontS36 color-0d0 mb-14">求职期望</div>
						<div class="iconfont icon-tianjia fontS36 ml-auto"></div>
					</div>
					<div v-for="(item, index) in postForm.resumeExpectList" :key="index"
						class="flex-center mb-20 bg-f7 p-20" @click="toEdit('expect', item.id)"
						@longpress="handleDelExpect(item)">
						<div>
							<div class="fontS32 font-500 color-0d0 lh-52">{{ item.expectTypeName || '' }}</div>
							<div class="flex-center fontS28 mt-2 lh-52">
								<div>{{ item.professionName }}</div>
								<div class="ml-36">{{ item.minSalary || 0 }}K-{{ item.maxSalary || 0 }}K</div>

							</div>
							<div class="color-6 fontS24 lh-44 mt-2">{{ item.cityName || '' }}·{{ item.industryNames ||
								''
							}}
							</div>
						</div>
						<div class="ml-auto iconfont icon-youjiantou fontS28"></div>

					</div>
				</div>
				<div class="pt-34 pb-14 bor-b">
					<div class="flex-center">
						<div class="font-bold fontS36 color-0d0 mb-14">工作经历</div>
						<div class="iconfont icon-tianjia fontS36 ml-auto"
							@click="toEdit('creat2', '', postForm.id, null)"></div>
					</div>
					<div v-for="(item, index) in postForm.resumeWorkList" :key="index"
						class="flex-center mb-20 bg-f7 p-20" @click="toEdit('creat2', '', postForm.id, item, 'edit')"
						@longpress="handleDelExperce(item)">
						<div style="width: calc(100% - 40upx);">
							<div class=" color-0d0 lh-52 flex-center">
								<div class="fontS32 font-500">{{ item.companyName || '' }}</div>
								<div v-if="item.isInternship" class="isInternship ml-10">实习</div>
								<div class="ml-auto fontS24 color-6">{{ item.startWorkDate || '' }} - {{
									item.endWorkDate || ''
								}}
								</div>
							</div>
							<div>{{ item.professionName || '' }}</div>


							<div class="color-6 fontS24 lh-44 mt-2 fontE1">工作内容：{{ item.workContent || '' }}</div>
							<!-- 职业优势 -->
							<div></div>
						</div>
						<div class="ml-auto iconfont icon-youjiantou fontS28">
						</div>

					</div>
				</div>
				<div class="pt-34 pb-14 bor-b">
					<div class="flex-center">
						<div class="font-bold fontS36 color-0d0 mb-14">教育经历</div>
						<div class="iconfont icon-tianjia fontS36 ml-auto"
							@click="toEdit('creat3', '', postForm.id, null)"></div>
					</div>
					<div v-for="(item, index) in postForm.resumeEducationList" :key="index"
						class="flex-center mb-20 bg-f7 p-20" @click="toEdit('creat3', '', postForm.id, item, 'edit')"
						@longpress="handleDelEdu(item)">
						<div style="width: calc(100% - 40upx);">
							<div class="color-0d0 lh-52 flex">
								<div class="fontS32 font-500">{{ item.schoolName || '' }}</div>
								<div class="ml-auto fontS24 color-6">{{ item.minStudyDate || '' }} - {{
									item.maxStudyDate || ''
								}}
								</div>
							</div>
							<div>{{ item.educationName || '' }} · {{ item.majorName || "" }} · {{ item.customMajorName
								||
								'' }}
							</div>
							<div class="color-6 fontS24 lh-44 mt-2 fontE1">在校经历：{{ item.schoolExperience || '' }}</div>
						</div>
						<div class="ml-auto iconfont icon-youjiantou fontS28"></div>

					</div>
				</div>
				<div class="pt-34 pb-14">
					<div class="font-bold fontS36 color-0d0 mb-14">资格证书</div>
					<image v-if="postForm.certificate" @click="uploadSent" class="certImg" mode="aspectFill"
						:src="baseUrl + postForm.certificate" />
					<div @click="uploadSent" v-else class="certImg flex align-center justify-center">
						<div class="iconfont icon-tianjia color-green fontS46 text-center"></div>
					</div>
				</div>



			</div>
		</scroll-view>
		<div class="bottom">
			<div class="submitBtn fontS26" @click="preView">预览
			</div>

		</div>



	</view>
</template>

<script>
const ossUploadFile = require("@/utils/ossupload/upload").ossUploadFile;
import { onLineResume, editSeekJobStatus, editCertificate, delResumeEducation, delResumeWork, resumeExpectUnBind } from '@/api/resume'
const api = require("@/api/api.js").api;
export default {
	computed: {
		userInfo() {
			console.log(this.$store.getters.userInfo)
			return this.$store.getters.userInfo || {};
		},
	},
	data() {
		return {
			baseUrl: getApp().globalData.baseUrl,
			postForm: null,
			jobSeekValue: null,
			value: '',
			sexList: getApp().globalData.sexList,
			eduList: getApp().globalData.education,
			experienceList: getApp().globalData.experience,
			jobSeekList: getApp().globalData.jobSeek,
			regionList: [],
			postStatus: false
		}
	},
	onLoad() {
		// this.getRegion()

	},
	onShow() {
		this.getonLineResume()
	},
	methods: {
		async uploadSent(type) {
			let _this = this;
			uni.chooseImage({
				count: 1, // 默认选择一个文件
				sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
				sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
				success: (res) => {

					console.log(res.tempFilePaths)
					this.uploadImages(res.tempFilePaths[0])
				},
				fail: (err) => {
					console.error('选择文件失败', err);
				}
			});
		},
		async uploadImages(path, type) {
			let data = { type: 10 };
			data.filePath = path
			ossUploadFile.ossUploadFile(data, async (res) => {
				this.postForm.certificate = res.fileName
				const { data } = await editCertificate(this.postForm);
				this.getonLineResume()
			}, async (error) => {
				console.log(error)

			})
		},
		async getonLineResume() {
			const { data } = await onLineResume()
			this.jobSeekList.forEach((item, i) => {
				if (Number(item.value) === data.jobSeekStatus) {
					this.jobSeekValue = i
				}
			})
			this.postForm = data
		},
		async getRegion() {
			const { data } = await api.region.regionList()
			this.regionList = data
		},
		async change(e, type) {
			if (type === 'jobSeek') {
				this.jobSeekValue = e.detail.value;
				this.postForm.jobSeekStatus = this.jobSeekList[this.jobSeekValue].value


			}
			const { data } = await editSeekJobStatus(this.postForm)

		},
		async toEdit(url, typeId, resumeId, item, flag) {
			uni.navigateTo({
				url: `${url}?resumeId=${resumeId}&id=${typeId}&page=edit&item=${item ? JSON.stringify(item) : ''}&flag=${flag}`
			})
		},

		async preView() {
			uni.navigateTo({
				url: '/pages/resume/resume'
			})
		},
		async handleDelEdu(item) {
			let _this = this
			uni.showModal({
				title: '提示',
				content: '是否删除当前教育经历？',
				confirmColor: '#37AF71',
				success: async function (res) {
					if (res.confirm) {
						const { data } = await delResumeEducation(item.id)
						uni.showToast({ title: '删除成功', icon: 'none' })
						await _this.getonLineResume()
					} else if (res.cancel) {

					}
				}
			});
		},
		async handleDelExperce(item) {
			let _this = this
			uni.showModal({
				title: '提示',
				content: '是否删除当前工作经历？',
				confirmColor: '#37AF71',
				success: async function (res) {
					if (res.confirm) {
						const { data } = await delResumeWork(item.id)
						uni.showToast({ title: '删除成功', icon: 'none' })
						await _this.getonLineResume()
					} else if (res.cancel) {

					}
				}
			});
		},
		async handleDelExpect(item) {
			let _this = this;
			uni.showModal({
				title: '提示',
				content: '是否解绑当前求职期望？',
				confirmColor: '#37AF71',
				success: async function (res) {
					if (res.confirm) {
						const { data } = await resumeExpectUnBind({
							expectId: item.id,
							resumeId: _this.postForm.id
						})
						uni.showToast({ title: '解绑成功', icon: 'none' })
						await _this.getonLineResume()
					} else if (res.cancel) {

					}
				}
			});
		}
	},


}
</script>

<style lang="less" scoped>
.content {
	display: flex;
	flex-direction: column;
	background: #fff;
	padding: 20upx;

}

.bottom {
	box-shadow: 0px 6upx 24upx 0px rgba(0, 78, 52, 0.12);
	padding-bottom: calc(constant(safe-area-inset-bottom) + 22upx);
	/*兼容 IOS<11.2*/
	padding-bottom: calc(env(safe-area-inset-bottom) + 22upx);
	/*兼容 IOS>11.2*/
}

.headImg {
	min-width: 110upx;
	min-height: 110upx;
}

.color-0d0 {
	color: #0D0D12;
}

.isInternship {
	height: 32upx;
	line-height: 28upx;
	border-radius: 8upx;
	border: 1px solid #FF6601;
	color: #FF6601;
	font-size: 22upx;
	padding: 0 10upx;

}

.certImg {
	width: 100%;
	height: 300upx;
	padding: 20upx;
	border-radius: 8upx;
	border: 1px dashed #34A76C;
}

.bg-f7 {
	background: #f7f8f7;
}
</style>